package mysemaphore;

import java.util.concurrent.Semaphore;

public class SemaphoreDir implements  Runnable {
    //获得对象
    Semaphore s = new Semaphore(2);
    @Override
    public void run() {
        try {
            s.acquire();
            System.out.println("开始行驶");
            Thread.sleep(1000);
            System.out.println("归还通行证");
            s.release();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
